package org.easyx.api.base;

import org.easyx.core.utils.AjaxRetKit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;

public class ApiBaseController {
	private static final Logger log = LoggerFactory.getLogger(ApiBaseController.class);
	
	/** 异常处理 */
	@ExceptionHandler  
	public Object exp(Exception ex){
		log.error("系统出现异常："+ex.getMessage());
		return AjaxRetKit.renderError("哎哟喂！系统的脑子有点乱...");
	}
	
	/**
	 * Ajax失败响应
	 * @param msg
	 * @return
	 */
	protected Object operateError() {
		return operateError("哎哟喂！系统的脑子有点乱...");
	}
	
	/**
	 * Ajax失败响应
	 * @param msg
	 * @return
	 */
	protected Object operateError(String msg) {
		return AjaxRetKit.renderError(msg);
	}
	
	/**
	 * Ajax成功响应
	 * @param msg
	 * @param obj
	 * @return
	 */
	protected Object operateSuccess(String msg,Object obj) {
		return AjaxRetKit.renderSuccess(msg, obj);
	}
	
	/**
	 * Ajax成功响应
	 * @param msg
	 * @return
	 */
	protected Object operateSuccess(String msg) {
		return AjaxRetKit.renderSuccess(msg);
	}
}
